﻿/// <reference path="../common.js" />
/// <reference path="template-web.js" />

template.defaults.rules.push({
    test: /\${([\w\W]*?)}/,
    use: function (match, code) {
        return {
            code: code,
            output: 'escape'
        }
    }
});
template.defaults.rules.push({
    test: /\$${([\w\W]*?)}/,
    use: function (match, code) {
        return {
            code: code,
            output: 'raw'
        }
    }
});
//
template.defaults.imports.to_date = function (thiso, type) {
    if (type === undefined) {
        return moment(thiso).format("YYYY-MM-DD HH:mm:ss");
    }
    return moment(thiso).format(type);
};
template.defaults.imports.to_datemin = function (thiso, type) {
    if (type === undefined) {
        var year = moment(thiso).format("YYYY");
        if (year == "1753") { return "" }
        else {
            return moment(thiso).format("YYYY-MM-DD HH:mm:ss");
        }
    }
    return moment(thiso).format(type);
};
//
template.defaults.imports.to_dateNow = function (thiso, type) {
    if (type === undefined) {
        return moment(thiso, "YYYYMMDD").fromNow();
    }
    return moment(thiso).format(type);
};

template.defaults.imports.to_dateStartOf = function (thiso, type) {
    if (type === undefined) {
        return moment(thiso).startOf("day").fromNow();
    }
    return moment(thiso).format(type);
};
template.defaults.imports.url_token = function (thiso) {
    var rpstr = new Array("f", "s", "x", "c", "t", "o", "h", "m", "p", "a");
    var form = String(thiso);
    for (var i = 0; i < rpstr.length; i++) {
        form = form.replace("" + i + "", rpstr[i]);
    }
    return form;
}

template.defaults.imports.radio_checked = function (thiso, checkvalue) {
    if (thiso == checkvalue) { return 'checked="checked"'; }
    return "";
}